﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    ViewBag.Title = "ZKTS";
    Layout = null;
}
@{
    if (Model.StandardConfig == null)
    { 
    <text>考核目标未配置</text>
        return;
    }
    List<dynamic> list = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {

        list.Add(new
        {
            时间 = dt,
            考核目标 = Model.GetConfig(dt.Year, dt.Month).预约成功率目标,
            预约成功率 = Model.GetAvgYYCGL(dt.Year, dt.Month)
        });
    } 

    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Width = 600;
    ChartModel.Height = 400;
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.IsRate = true;
    ChartModel.YAxis = "百分率";

    foreach (var item in list.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "考核目标";
    foreach (var item in list)
    {
        series.Data.Add(item.考核目标);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "预约成功率";
    foreach (var item in list)
    {
        series1.Data.Add(item.预约成功率);
    }
    ChartModel.Serieses.Add(series1);

    var 服务顾问人数 = Model.SADayData.GroupBy(o => o.EmployeeId).Count();

    var 累计完成入厂台次 = Model.SADayData.Sum(o => o.WXRCTC_MaintentceToFactory + o.SGRCTC_AccidentToFactory);
    var 累计完成入厂台次平均 = 服务顾问人数 == 0 ? 0 : Math.Round(((decimal)累计完成入厂台次 / 服务顾问人数), 0, MidpointRounding.AwayFromZero);

    var 电话成功预约回厂数 = Model.SADayData.Sum(o => o.DHCGYYHCS);
    var 电话成功预约回厂数平均 = 服务顾问人数 == 0 ? 0 : Math.Round(((decimal)电话成功预约回厂数 / 服务顾问人数), 0, MidpointRounding.AwayFromZero);

    var 累计实现预约回厂数 = Model.SADayData.Sum(o => o.SXYYHCS);
    var 累计实现预约回厂数平均 = 服务顾问人数 == 0 ? 0 : Math.Round(((decimal)累计实现预约回厂数 / 服务顾问人数), 0, MidpointRounding.AwayFromZero);
        

    Model.SADayDatas = Model.SADayData;
    Model.MonthTargets = Model.MonthTarget;
    Model.StandardConfigs.Add(Model.StandardConfig);
    
}
<div style="height: 100%; overflow: auto">
    @Html.Action("ReportBar", "Common", Model.BarModel)
    <div style="position: relative; width: 100%">
        <div class="pagetitle">
            预约成功率对比</div>
        <table width="100%">
            <tr>
                <td style="width: 50px">
                    &nbsp;
                </td>
                <td valign="top">
                    <p style=" padding-bottom:15px; font-size:15px;">@(Model.BarModel.Month.Month)月预约成功率</p>
                    <table class="reporttable" style="border-collapse: collapse;">
                        <thead>
                            <tr>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        售 后 前 台 接 待 姓 名
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        接 待 前 台 职 业 资 质
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        累 计 完 成 入 厂 台 次
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        电 话 成 功 预 约 回 厂 数
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        累 计 实 现 预 约 回 厂 数
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        预 约 成 功 率
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        失约率
                                    </div>
                                </th>
                            </tr>
                        </thead>
                        @foreach (var item in Model.SADayData.GroupBy(o => o.EmployeeId))
                        {
                            <tr>
                                <td>@item.FirstOrDefault().Employee.Name
                                </td>
                                <td>@(item.FirstOrDefault().Employee.WorkYear)年
                                </td>
                                <td>@item.Sum(o=>o.SGRCTC_AccidentToFactory+o.WXRCTC_MaintentceToFactory)
                                </td>
                                <td>
                                    @item.Sum(o=>o.DHCGYYHCS)
                                </td>
                                <td>
                                    @item.Sum(o=>o.SXYYHCS)
                                </td>
                                <td @if (Model.StandardConfig.招徕实施率目标 > Model.GetYYCGL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>@Model.GetYYCGL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                                </td>
                                <td @if (Model.StandardConfig.失约率目标 < Model.GetSYL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>@Model.GetSYL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                                </td>
                            </tr>
                        }
                        <tr>
                            <td colspan="2">
                                服务接待平均数
                            </td>
                            <td>
                            @累计完成入厂台次平均
                            </td>
                            <td>
                           @电话成功预约回厂数平均
                            </td>
                            <td>
                            @累计实现预约回厂数平均
                            </td>
                            <td>
                                @Model.GetAvgYYCGL(Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                            </td>
                            <td>
                                @Model.GetAvgSYL(Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                服务接待目标总数
                            </td>
                            <td>
                               @累计完成入厂台次
                            </td>
                            <td>
                                @电话成功预约回厂数
                            </td>
                            <td>
                                @累计实现预约回厂数
                            </td>
                            <td>
                                @if (Model.StandardConfig != null)
                                {
                                    @Math.Round(@Model.StandardConfig.预约成功率目标, 1)<text>%</text>
                                }
                            </td>
                            <td>
                                @if (Model.StandardConfig != null)
                                {
                                    @Math.Round(@Model.StandardConfig.失约率目标, 1)<text>%</text>
                                }
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    @Html.Partial("../Chart/Line", ChartModel)
                </td>
            </tr>
        </table>
    </div>
</div>
